package com.tangtang.core;

public class TypeConvertUtil {

    public static Integer toInterger(String text) {
        try {
            return new Integer(text);
        } catch (NumberFormatException e) {
            return null;
        }
    }

    public static Integer toInterger(String text, Integer defVal) {
        try {
            return new Integer(text);
        } catch (NumberFormatException e) {
            return defVal;
        }
    }

    public static Integer toInterger(Object text) {
        if (text == null) {
            return null;
        }
        try {
            return new Integer(text.toString().trim());
        } catch (NumberFormatException e) {
            return null;
        }
    }

    public static Integer toInterger(Object text, Integer defVal) {
        if (text == null) {
            return null;
        }
        try {
            return new Integer(text.toString().trim());
        } catch (NumberFormatException e) {
            return defVal;
        }
    }

    public static Double toDouble(String text) {
        try {
            return new Double(text);
        } catch (NumberFormatException e) {
            return null;
        }
    }

    public static Double toDouble(String text, Double defVal) {
        try {
            return new Double(text);
        } catch (NumberFormatException e) {
            return defVal;
        }
    }

    public static Double toDouble(Object text) {
        if (text == null) {
            return null;
        }
        try {
            return new Double(text.toString().trim());
        } catch (NumberFormatException e) {
            return null;
        }
    }

    public static Double toDouble(Object text, Double defVal) {
        if (text == null) {
            return null;
        }
        try {
            return new Double(text.toString().trim());
        } catch (NumberFormatException e) {
            return defVal;
        }
    }
}
